/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.serli.sample.peopleapp;

import com.serli.sample.person.model.data.Gender;
import com.serli.sample.person.model.data.Person;
import com.serli.sample.person.model.service.PeopleServiceRemote;
import java.util.Date;
import java.util.Hashtable;
import java.util.List;
import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;

/**
 *
 * @author serli
 */
public class CallEJB {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws Exception {

        Properties p = new Properties();
        p.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
        p.put(Context.PROVIDER_URL, "jnp://localhost:1099");
        p.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
        InitialContext ctx = new InitialContext(p);

        PeopleServiceRemote psr = (PeopleServiceRemote) ctx.lookup("people-model-ear-1.0/PeopleService/remote");

        try {
            System.out.println("TEST SetPerson");
            psr.testRemoteSetPerson(new Person("MERON", "Pascal", new Date(), Gender.MALE));
            System.out.println("\t[ OK ]");
        } catch (Exception ex) {
            System.out.println("\t[ ERROR ] : " + ex.getMessage());
        }
        try {
            System.out.println("TEST GetPerson");
            Person person = psr.testRemoteGetPerson();
            System.out.println("firstName is " + person.getFirstName());
            System.out.println("\t[ OK ]");
        } catch (Exception ex) {
            System.out.println("\t[ ERROR ] : " + ex.getMessage());
        }
        try {
            System.out.println("TEST Set and Get simple object (Object)");
            psr.testRemoteObject(new String("String test"));
            System.out.println("\t[ OK ]");
        } catch (Exception ex) {
            System.out.println("\t[ ERROR ] : " + ex.getMessage());
        }
        try {
            System.out.println("TEST Set and Get Primitif (int)");
            psr.testRemotePrimitif(1979);
            System.out.println("\t[ OK ]");
        } catch (Exception ex) {
            System.out.println("\t[ ERROR ] : " + ex.getMessage());
        }

    }
}
